package com.k.ums.context;

import lombok.Data;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Locale;
import java.util.Map;

/**
 * @Description:
 * @Author: kt
 * @CreateTime: 2022/1/8
 */
@Data
public class UmsContext {

    private ApplicationContext delegator;

    private ConfigurableListableBeanFactory beanFactory;

    public UmsContext() {
    }

    public UmsContext(ApplicationContext delegator, ConfigurableListableBeanFactory beanFactory) {
        this.delegator = delegator;
    }

    public String getApplicationName() {
        return delegator.getApplicationName();
    }

    public String getDisplayName() {
        return delegator.getDisplayName();
    }

    public Object getBean(String name) throws BeansException {
        return delegator.getBean(name);
    }

    public <T> T getBean(String name, Class<T> requiredType) throws BeansException {
        return delegator.getBean(name, requiredType);
    }

    public Object getBean(String name, Object... args) throws BeansException {
        return delegator.getBean(name, args);
    }

    public <T> T getBean(Class<T> requiredType) throws BeansException {
        return delegator.getBean(requiredType);
    }

    public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException {
        return delegator.getBean(requiredType, args);
    }

    public void publishEvent(Object event) {
        delegator.publishEvent(event);
    }

    public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
        return delegator.getMessage(code, args, defaultMessage, locale);
    }

    public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
        return delegator.getMessage(code, args, locale);
    }

    public String getMessage(MessageSourceResolvable messageSourceResolvable, Locale locale) throws NoSuchMessageException {
        return delegator.getMessage(messageSourceResolvable, locale);
    }

    public Environment getEnvironment() {
        return delegator.getEnvironment();
    }

    public Resource[] getResources(String locationPattern) throws IOException {
        return delegator.getResources(locationPattern);
    }


}
